<?php

/**
 * instruction-paie/index.phtml
 */
?>
<?php
$title = "Instruction de Paie";
$this->headTitle($title);
$site	 = $this->site;
$periode = $this->periode;
?>
<div class="content-head">
    <h3><?php echo $title ?> pour le
	site <a href="#" id="instruction-site" data-type="select"><?php echo $site->libelle ?></a>
	Période <a href="#" id="instruction-periode" data-type="select"><?php echo $periode->libelle; ?></a>
	<span id="ajax-loader" class="hide" style="margin-left: 10px;">
	    <img src="<?php echo $this->basePath();?>/img/rhx/ajax-loader.gif" width="32" height="32">
	</span>
    </h3>
    
</div>

<form id="formData" action="#" method="post">
    <input type="hidden" id="form-site" name="site" value="<?php echo $site->id; ?>">
    <input type="hidden" id="form-periode" name="periode" value="<?php echo $periode->id; ?>">
</form>

<div class="content-body">
    <div id="content-data">
	<!-- AJAX CONTENT -->
	<?php echo $this->loadIndex; ?>
    </div>
</div>

<script type="text/javascript">
    /* Au chargement */
    $(function(){
	// editable
	$('#instruction-site').editable({
	    title: 'Site',
	    source: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonSiteList')) ?>',
	    validate: function(value){
		val = parseInt(value);
		$('#form-site').val(val);
		changeSite(val);
		loadIndex();
	    }
	});
	$('#instruction-periode').editable({
	    title: 'Periode',
	    source: '<?php echo $this->url('RHX/default', array('controller'	 => 'variable', 'action'	 => 'jsonPeriodeList')) ?>',
	    validate: function(value){
		$('#form-periode').val(value);
		changePeriode(value);
		loadIndex();
	    }
	});
    });

    function loadIndex(){
	site = $('#form-site').val();
	if(parseInt(site) < 0){
	    return loadIndexTotal();
	}
	periode = $('#form-periode').val();
	$('#ajax-loader').show('fast');
	$('#content-data').fadeOut('fast');
	ajax = $.ajax({
	    type: 'post',
	    url : '<?php echo $this->url('RHX/default', array('controller'	 => 'InstructionPaie', 'action'	 => 'loadIndex')) ?>/' + site + '/' + periode,
	    data: $('#formData').serialize()
	});
	ajax.done(function(data){
	    $('#content-data').hide().delay(500).fadeIn('normal').html(data);
	    $('#ajax-loader').hide('slow');
	});
    }
    
    function loadIndexTotal(){
	//alert("Chargement de tous les sites");
	periode = $('#form-periode').val();
	$('#ajax-loader').show('fast');
	$('#content-data').fadeOut('fast');
	ajax = $.ajax({
	    type: 'post',
	    url : '<?php echo $this->url('RHX/default', array('controller'	 => 'InstructionPaie', 'action'	 => 'loadIndexTotal')) ?>/' + 99 + '/' + periode,
	    data: $('#formData').serialize()
	});
	ajax.done(function(data){
	    $('#content-data').hide().delay(500).fadeIn('normal').html(data);
	    $('#ajax-loader').hide('slow');
	});
	return false;
    }
</script>